﻿
using System.Collections.Generic;
using JetBrains.ReSharper.Psi.CSharp.Tree;
using Twins.Infrastructure;
using Twins.Interface;
using Twins.Interface.IHandler;

namespace Twins.Classes.Hanlder.HanlderStatement
{
    public class HanlderForIWhileStatement : IHandler<IWhileStatement>
    {
        public IEnumerable<ILineCode> DoFor(IWhileStatement whileStatement)
        {
            var hashLineCode = whileStatement.WhileKeyword.GetText();
            var receiveHashLineCodeFromProcesserCSharpExpression = IoC
                .Resolve<IReceiveHashLineCodeFromProcesserCSharpExpression>();
            receiveHashLineCodeFromProcesserCSharpExpression
                .ReceiveHashLineCode(whileStatement.Condition, ref hashLineCode);
            var receiveHashLineCodeFromProcesserCSharpStatement = IoC
                .Resolve<IReceiveHashLineCodeFromProcesserCSharpStatement>();
            return receiveHashLineCodeFromProcesserCSharpStatement
                .ReceiveHashLineCode(whileStatement, whileStatement.Body, hashLineCode); 
        }

        public IEnumerable<ILineCode> DoFor(object obj)
        {
            return DoFor((IWhileStatement)obj);
        }

    }
}
